//
//  UserCarViewController.m
//  Manage
//
//  Created by 杨康 on 2017/11/15.
//  Copyright © 2017年 杨康. All rights reserved.
//

#import "UserCarViewController.h"
#import "EvDetailsViewController.h"
#import "DeviceModel.h"
@interface UserCarViewController ()
@property(nonatomic,strong)ykTableView *tableView;
@end

@implementation UserCarViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getCarList];
}
-(void)getCarList
{
    NSString *URLString = @"/axq/admin/device/user";
    NSDictionary *parameters = @{@"peopleid": self.peopleid};
    [NetworkPath requestWithMethod:0 andURLString:URLString andParameters:parameters RequestSuccess:^(NSURLResponse *response, id responseObject) {
        NSLog(@"%@",responseObject);
        self.tableView.className=@"EvmCell";
        NSMutableArray *itemArr=[NSMutableArray array];
        NSString *code=[NetworkPath getValue:@"code" from:responseObject];
        if (code.length) {
            if([code isEqualToString:@"10008"])
            {
                if ([NetworkPath isNSArray:@"data" from:responseObject]) {
                    NSArray *data=responseObject[@"data"];
                    for (int i=0; i<data.count; i++) {
                        if ([data[i] isKindOfClass:[NSDictionary class]]) {
                            DeviceModel *model=[DeviceModel modelWithDict:data[i]];
                            EvmData *dataObj=[[EvmData alloc]init];
                            if (![NSString isNULLString:model.img1]) {
                                dataObj.image=model.img1;
                            }else
                            {
                                if (![NSString isNULLString:model.img2]) {
                                    dataObj.image=model.img2;
                                }else
                                {
                                    if (![NSString isNULLString:model.img3]) {
                                        dataObj.image=model.img3;
                                    }else
                                    {
                                        dataObj.image=@"";
                                    }
                                }
                            }
                            dataObj.name=model.devicename;
                            dataObj.storeName=model.shopname;
                            dataObj.brand=model.brandname;
                            dataObj.color=model.color;
                            dataObj.state=model.status;
                            dataObj.model=model;
                            [itemArr addObject:dataObj];
                        }
                    }
                }
            }else
            {
                NSString *str=[NetworkPath getValue:@"msg" from:responseObject];
                
                [self.view makeToast:str];
            }
        }
        [self.tableView.dataArray addObject:itemArr];
        [self.tableView reloadData];
    } RequestFailed:^(NSError *error) {
        self.tableView.className=@"EvmCell";
        NSMutableArray *itemArr=[NSMutableArray array];
        [self.tableView.dataArray addObject:itemArr];
        [self.tableView reloadData];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"电动车管理";
    UIButton *leftButton=(UIButton *)self.navigationItem.leftBarButtonItem.customView;
    leftButton.selected=YES;
    
    
    self.tableView=[SingLeton myTableViewWithFrame:CGRectMake(0, TOP_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-TOP_HEIGHT) withRefresh:NO didSelect:^(ykTableView *tableView, NSIndexPath *indexPath) {
        EvmCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        EvDetailsViewController *vc=[[EvDetailsViewController alloc]init];
        vc.deviceid=cell.dataDic.model.deviceid;
        vc.type=@"用户管理";
        [self.navigationController pushViewController:vc animated:YES];
    }];
    [self.view addSubview:self.tableView];
    

    
    
}





@end
